# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=gcc
_target=avr

pkgbase=mingw-w64-${_target}-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}
pkgver=8.4.0
pkgrel=3
pkgdesc='GNU compiler collection for AVR 8-bit and 32-bit microcontrollers (mingw-w64)'
arch=('any')
license=('GPL')
url='https://www.gnu.org/software/gcc/gcc.html'
options=(!strip)
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
depends=(
    "${MINGW_PACKAGE_PREFIX}-${_target}-binutils"
    "${MINGW_PACKAGE_PREFIX}-gmp"
    "${MINGW_PACKAGE_PREFIX}-isl"
    "${MINGW_PACKAGE_PREFIX}-mpc"
    "${MINGW_PACKAGE_PREFIX}-mpfr"
)
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz")
sha256sums=('e30a6e52d10e1f27ed55104ad233c30bd1e99cfb5ff98ab022dc941edd1b2dd4')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}

    mkdir ${_realname}-build
}

build() {
    cd ${srcdir}/${_realname}-${pkgver}/${_realname}-build

    ../configure \
        --build=${MINGW_CHOST} \
        --prefix=${MINGW_PREFIX} \
        --target=${_target} \
        --enable-languages=c,c++ \
        --disable-nls \
        --disable-libssp \
        --disable-shared \
        --disable-threads \
        --disable-libgomp \
        --disable-libada \
        --with-dwarf2 \
        --enable-mingw-wildcard
    make
}

package() {
    cd ${srcdir}/${_realname}-${pkgver}/${_realname}-build

    make DESTDIR="$pkgdir" install

    cd ${pkgdir}${MINGW_PREFIX}

    # strip debug symbols from libraries
    find lib -type f -name "*.a" -exec ${MINGW_PREFIX}/bin/${_target}-strip --strip-debug '{}' \;

    # info and man7 files conflict with native gcc
    rm -rf share/info share/man/man7
}
